<!DOCTYPE html>
<html>

<head>
    <title>游记列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css">
    <script src="/js/plugins/dialog/dialog.min.js"></script>
    <script src="/js/common.js"></script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜酒店">
            </div>
        </div>
    </div>
</div>


<!--<div class="container">-->
<!--<h6>每月冠军游记</h6>-->
<!--<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">-->
<!--<div id="travelsCommends" class="carousel-inner" render-loop="list">-->

<!--<div class="carousel-item">-->
<!--<div class="border commend">-->
<!--<a render-key="list.travelId" render-fun="handle">-->
<!--<img render-src="list.coverUrl" width="100%" height="200px">-->
<!--<h1 render-html="list.title"></h1>-->
<!--<small render-html="list.subTitle"></small>-->
<!--</a>-->
<!--</div>-->
<!--</div>-->

<!--</div>-->

<!--<a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">-->
<!--<span class="carousel-control-prev-icon" aria-hidden="true"></span>-->
<!--<span class="sr-only"></span>-->
<!--</a>-->
<!--<a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">-->
<!--<span class="carousel-control-next-icon" aria-hidden="true"></span>-->
<!--<span class="sr-only"></span>-->
<!--</a>-->
<!--</div>-->
<!--</div>-->

<div class="container" id="allTravels">
    <h6>全部酒店</h6>
    <div render-loop="list">

        <div class="row detail">
            <div class="col">
                <a render-key="list.id" render-fun="handle">
                    <h4 render-html="list.name"></h4>
                </a>
                <p>
                    <a href="userProfiles.html">
                        <!--<img class="rounded-circle head-img" render-src="list.author.headImgUrl">-->
                        <span render-html="list.price" class="money"></span> </a> 在
                    <span class="addr" render-html="list.place.name"></span>

                </p>

                <p>
                    <i class="fa fa-eye fa-fw"></i>
                    <span>0</span>
                    <i class="fa fa-commenting fa-fw"></i>
                    <span>0</span>
                </p>
            </div>
            <div class="col bigimg">
                <a render-key="list.id" render-fun="handle">
                    <img render-src="list.coverUrl">
                </a>
            </div>
        </div>

    </div>
</div>

<script>
    $(function () {
        var keyword = sessionStorage.getItem("keyword");
        var maxPrice = getParams().maxPrice;
        var placeId = getParams().placeId;
        var param={placeId:placeId};
        var currentPage = 1; //当前页
        var travels; //当前页面的游记
        var pages; //总页数
        var keywordFlag;
        if (keyword){//如果关键字有值
            keywordFlag=true;
            $(".searchBtn").val(keyword);
            param={keyword:keyword,placeId:placeId};
            if (maxPrice){//如果最高价有值
                param={keyword:keyword,maxPrice:maxPrice,placeId:placeId};
            }
        }else if (maxPrice){//如果关键字没值,最高价有值
            param={maxPrice:maxPrice,placeId:placeId};
        }


        //高级查询
        //设置查询框点击事件
        $(".searchBtn").click(function () {
            currentPage = 1;
        });
        //设置查询框的值改变事件
        //发送ajax请求获取筛选过的已发布游记
        $(".searchBtn").change(function () {
                param.keyword=$(this).val();
            // if (keywordFlag){
            // } else {
            // }
            $.get("/hotels/",param, function (data) {
                renderView(data);
                travels = data.list;
                pages = data.pages;
            });
        });
        //发送ajax请求获取已发布游记
        $.get("/hotels",param, function (data) {
            //渲染界面
            renderView(data);
            travels = data.list;
            pages = data.pages;
        });

        // 设置窗口的滚动事件
        $(window).scroll(function () {
            //取出当前查询框的值
            var keyword= $(".searchBtn").val();
            if (isFull()) {
                //判断当前不是最后一页
                if (currentPage < pages) {
                    param.currentPage=++currentPage;
                    $.get("/hotels", param, function (data) {
                        //叠加之前的游记数据
                        $.merge(travels, data.list);
                        //再次渲染界面
                        renderView({list: travels});
                    });
                } else {
                    //提示到底了
                    $(document).dialog({
                        type : "notice",
                        infoText: "没有下一页,到底了",
                        autoClose: 1500,
                        position: "bottom"
                    });
                }
            }
        });

        function renderView(data) {
            $("#allTravels").renderValues(data, {
                handle: handle
            });

            $.each($(".money"), function (index, ele) {
                var price = $(this).html();
                // console.log(price);
                $(this).html("平均价格:¥" + price);
            });
        }

        // //设置当前月推荐的游记
        // $.get("/travels/commends", {type: 2}, function (data) {
        //     //渲染界面
        //     $("#carouselExampleControls").renderValues({list: data}, {
        //         handle: handle
        //     });
        //     //默认显示第一个推荐
        //     $(".carousel-item:first").addClass("active");
        // });

        function handle(ele, val) {
            ele.href = "/hotel/hotelContent.html?id=" + val;
        }
    });
</script>
</body>
</html>